package com.oocl.im.handler.impl;

import com.oocl.im.entity.Client;
import com.oocl.im.constants.ServerConstants;
import com.oocl.im.constants.ServerMap;
import com.oocl.im.entity.Protocol;
import com.oocl.im.handler.IHandle;
import com.oocl.im.outputstream.impl.NetOutput;

import java.io.ObjectOutputStream;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by LIBA2 on 7/13/2017.
 */
public class GroupChatHandle implements IHandle {
    ObjectOutputStream oos;

    public GroupChatHandle(ObjectOutputStream oos) {
        this.oos = oos;
    }

    @Override
    public void handle(Client client,Protocol protocol) {
        System.out.println("here is in group chat handle");
//        int groupId = Integer.parseInt((String) protocol.getParams().get(ServerConstants.TO));
//        Map<Client, ObjectOutputStream> group = ServerMap.groupsMap.get(String.valueOf(groupId));
        protocol.setMsgType(ServerConstants.RECHAT);
        Iterator iterator = ServerMap.socketMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            new NetOutput((ObjectOutputStream) entry.getValue()).write(protocol);
        }
    }
}
